package com.test.teach.thread;

//隋唐演义的大戏舞台
public class Stage extends Thread {
	public void run() {
		System.out.println("欢迎观看隋唐演义！！");
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}

		System.out.println("大幕徐徐拉开..........");
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}

		System.out.println("话说隋朝末年，隋军与农民起义军杀的天昏地暗难解难分....");

		// 创建隋军和农民起义军的线程对象
		ArmyRunnable armyTaskOfSuiDynasty = new ArmyRunnable();
		ArmyRunnable armyTaskOfRevolt = new ArmyRunnable();
		// 创建线程对象
		Thread armyOfSuiDynasty = new Thread(armyTaskOfSuiDynasty, "隋军");
		Thread armyOfRevolt = new Thread(armyTaskOfRevolt, "农民起义军");
		// 启动线程 让军队开始作战
		armyOfSuiDynasty.start();
		armyOfRevolt.start();

		// 舞台线程休眠，大家专心观看军队的厮杀
		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println("就当双方激战正酣，半路杀出个程咬金...");
		Thread mrCheng = new KeyPerson();
		mrCheng.setName("程咬金");

		System.out.println("程咬金的梦想就是能结束战争，是老百姓能够安居乐业！");
		// 军队停止下来
		// 使线程停止下来的方法

		/*
		 * 真正的大戏留给关键人物
		 */
		mrCheng.start();

		try {
			mrCheng.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		armyTaskOfSuiDynasty.keeprunning = false;
		armyTaskOfRevolt.keeprunning = false;

		try {
			Stage.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println("战争结束，人民安居乐业，程先生实现了他积极的人生梦想，为人民作出了贡献。");
		System.out.println("谢谢观赏我们的隋唐大戏！");

		// //鸣金收兵armyTaskOfSuiDynasty.keeprunning=false;
		// armyTaskOfRevolt.keeprunning=false;
		//
		//
		// try {
		// armyOfRevolt.join();
		// } catch (InterruptedException e) {
		// e.printStackTrace();
		// }
	}

	public static void main(String[] args) {
		new Stage().start();
	}

}
